﻿
Partial Class shopingList
    Inherits System.Web.UI.Page
    Private dt As System.Data.DataTable
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If (Not IsPostBack) Then
            GetData()
        End If
    End Sub

    Protected Sub GetData()
        Dim sbPU, sbCar As New StringBuilder
        Dim strSplit As Char() = New [Char]() {"$"}
        Dim idCollect As String()

        Dim sc As shopCar
        sc = CType(Session("shopCar"), shopCar)
        If (sc Is Nothing) Then
            Exit Sub
        End If
        Dim carList As System.Collections.Generic.List(Of String)
        carList = sc.GetValues()
        For Each Str As String In carList
            idCollect = Str.Split(strSplit)
            sbPU.AppendFormat(",'{0}'", idCollect(0).Trim())
            sbCar.AppendFormat(",'{0}'", idCollect(1).Trim())
        Next
        dt = Utility.GetSeleShopList( _
                        sbPU.ToString.Substring(1), _
                        sbCar.ToString.Substring(1))
        GV1.DataSource = dt
        GV1.DataBind()

    End Sub

    '--回去前一頁，必需要讓所選的東西不能掉..
    Protected Sub btn_back_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_back.Click
        Server.Transfer("pukl_auto.aspx")
    End Sub
    '--去結帳
    Protected Sub btn_closeing_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_closeing.Click
        Server.Transfer("shopClose.aspx")
    End Sub

    Protected Sub btn_cancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_cancel.Click
        Dim chk As CheckBox
        Dim lbl As Label

        Dim sc As shopCar
        If (Session("shopCar") Is Nothing) Then
            sc = New shopCar
        Else
            sc = CType(Session("shopCar"), shopCar)
        End If

        For Each row In GV1.Rows
            chk = CType(row.Cells(0).FindControl("chkShoping"), CheckBox)
            If Not (chk Is Nothing) Then
                If (chk.Checked) Then
                    lbl = CType(row.Cells(0).FindControl("lblPu_id"), Label)
                    'sc.Add(lbl.Text)
                    sc.RemoveValue(lbl.Text)
                End If
            End If
        Next
        Session("shopCar") = sc
        GetData()
    End Sub
    Protected Sub GV1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GV1.RowDataBound
        If (e.Row.RowType = DataControlRowType.DataRow) Then
            Dim lbl As Label
            lbl = CType(e.Row.Cells(0).FindControl("lblPu_id"), Label)
            lbl.Text = dt.Rows(e.Row.RowIndex)("PUID").ToString()
        End If
    End Sub
End Class
